#include<iostream>
#include<string>
using namespace std;
int a[30];
int main() {
   
    int n, m;
    while (cin >> n >> m) {
        if (n < 0) {
            cout << "-";
            n *= -1;
        }
        memset(a, 0, sizeof(a));
        int i = 0;
        while (n) {
            a[i++] = n % m;
            n /= m;
        }
        for (i--; i >= 0; i--) {
            if (a[i] < 10)
                cout << a[i];
            else if (a[i] == 10)
                cout << "A";
            else if (a[i] == 11)
                cout << "B";
            else if (a[i] == 12)
                cout << "C";
            else if (a[i] == 13)
                cout << "D";
            else if (a[i] == 14)
                cout << "E";
            else if (a[i] == 15)
                cout << "F";
        }
        cout << endl;
    }
    return 0;
}